//
//  WMParkInfoViewController.m
//  witMorning
//
//  Created by Mac mini on 2018/1/16.
//  Copyright © 2018年 zt. All rights reserved.
//

#import "WMParkInfoViewController.h"

@interface WMParkInfoViewController ()

@end

@implementation WMParkInfoViewController
{
    NSMutableArray *infoArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    if (!infoArray) {
        infoArray = [NSMutableArray arrayWithCapacity:0];
        
        [dataArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj[@"status"] integerValue] == 1) {
                [infoArray addObject:obj];
            }
        }];
    }
    [self createParkInfoView];
}

-(void)createParkInfoView{
    
    CGFloat itemNum = 4;
    
    CGFloat markW = (SCREEN_W-itemNum*2*15)/itemNum;
    CGFloat markH = markW/3;
    
    CGFloat x = 0;
    CGFloat y = 0;
    
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, SCREEN_W, CGRectGetHeight(self.view.frame)-20)];
    [self.view addSubview:scroll];
    
    for (int i = 0; i<infoArray.count; i++) {
        
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(15+x, y, markW, markH)];
        lab.text = [NSString stringWithFormat:@"%@",infoArray[i][@"parkNumber"]];
        lab.backgroundColor = RGB(52, 197, 50, 1);
        lab.textColor = [UIColor whiteColor];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.font = [UIFont systemFontOfSize:14];
        [scroll addSubview:lab];
        
        if (x+45+markW>SCREEN_W) {
            x = 0;
            y += markH+30;
        }else{
            x += (markW+30);
        }
    }
    
    [scroll setContentSize:CGSizeMake(0, y+markW)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
